#include "Buffer.hpp"
#include "../../base/Defind.hpp"

#include <cstring>
#include <cstdlib>

using namespace DBServer::Log;

Buffer::Buffer()
: cur(0), remain(LOGGER_BUFFER_SIZE)
{
    memset(buf, 0, LOGGER_BUFFER_SIZE);
}

auto Buffer::clear() -> void
{
    cur = 0;
    remain = total;
    memset(buf, 0, LOGGER_BUFFER_SIZE);
}

auto Buffer::append(const char *msg, int _size) -> void
{
    if (remain < _size) return;

    memcpy(buf+cur, msg, _size);
    cur += _size;
    remain -= _size;
}

auto Buffer::size() -> int
{
    return remain;
}
